﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Starcraft2.ReplayParser;

namespace StarCraft_2_Replay_Info
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void butRead_Click(object sender, EventArgs e)
        {
            if (File.Exists(textPfad.Text.Trim()))
            {
                readReplay(textPfad.Text.Trim());
            }
        }

        private void readReplay(string path)
        {
            Replay replay = Replay.Parse(path);
            labMap.Text = replay.Map;
            Player[] sPlayer = replay.Players;
            labPlayer.Text = sPlayer[0].Name + " vs. " + sPlayer[1].Name;
            labRase.Text = sPlayer[0].Race + " vs. " + sPlayer[1].Race;            
            if (sPlayer[0].IsWinner)
            {
                labWinner.Text = sPlayer[0].Name;
            }
            if (sPlayer[1].IsWinner)
            {
                labWinner.Text = sPlayer[1].Name;

            }
            labTyp.Text = getGametyp(replay.GameType);
            labLeght.Text = replay.GameLength.ToString("hh\\:mm\\:ss");
            labVer.Text = replay.ReplayVersion;
        }

        private string getGametyp(GameType type)
        {
            string sTyp = "";
            switch (type.ToString())
            {
                case "Open":
                    sTyp = "Offen";
                    break;
                case "Private":
                    sTyp = "Privat";
                    break;
                case "SinglePlayer":
                    sTyp = "Einzelspieler";
                    break;
            }
            return sTyp;
        }

        private void butPath_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);
            openFileDialog1.Filter = "SC2 Replay (*.SC2Replay)|*.SC2Replay";
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textPfad.Text = openFileDialog1.FileName;
            }
        }
    }
}
